package com.link.play.fit.ai.ui.weightcontrol.ac

import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.activity.addCallback
import androidx.lifecycle.ViewModelProvider
import com.link.play.fit.ai.R
import com.link.play.fit.ai.base.BaseActivity
import com.link.play.fit.ai.base.goToAc
import com.link.play.fit.ai.bean.UserGuide
import com.link.play.fit.ai.databinding.AcFastingGoalBinding

class FastingGoalAc : BaseActivity<AcFastingGoalBinding>(AcFastingGoalBinding::inflate) {

    val viewModel by lazy(LazyThreadSafetyMode.NONE) {
        ViewModelProvider(this)[WeighControlViewModel::class.java]
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModel.lastUserGuide = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            intent.getSerializableExtra("data", UserGuide::class.java) ?: UserGuide()
        } else {
            @Suppress("DEPRECATION")
            (intent.getSerializableExtra("data") as UserGuide?) ?: UserGuide()
        }

        onBackPressedDispatcher.addCallback {
            finish()
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)
        }
        binding.flBack.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }

        binding.card1.setOnClickListener {
            binding.v1.visibility = View.VISIBLE
            binding.v2.visibility = View.INVISIBLE
            binding.v3.visibility = View.INVISIBLE
            binding.tvNext.isEnabled = true
            viewModel.lastUserGuide.fastingGoal = 0
        }

        binding.card2.setOnClickListener {
            binding.v1.visibility = View.INVISIBLE
            binding.v2.visibility = View.VISIBLE
            binding.v3.visibility = View.INVISIBLE
            binding.tvNext.isEnabled = true
            viewModel.lastUserGuide.fastingGoal = 1
        }

        binding.card3.setOnClickListener {
            binding.v1.visibility = View.INVISIBLE
            binding.v2.visibility = View.INVISIBLE
            binding.v3.visibility = View.VISIBLE
            binding.tvNext.isEnabled = true
            viewModel.lastUserGuide.fastingGoal = 2
        }


        binding.tvNext.setOnClickListener {
            goToAc(FastingTimeAc::class.java) {
                putExtra("data", viewModel.lastUserGuide)
            }
            overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_to_left)
        }
    }
}